package com.admin;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointProperties;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ConfigurableApplicationContext;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 监控中心服务器启动入口
 *
 * @author yexi
 * @see AdminServerProperties
 * @see WebEndpointProperties
 * @see HealthEndpointProperties
 * @see WebEndpointAutoConfiguration
 */
@EnableAdminServer
@SpringBootApplication
@Slf4j
public class AdminServerApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(AdminServerApplication.class);
        Integer port = context.getBean(ServerProperties.class).getPort();
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        log.info("服务已启动，Admin UI访问地址：http://{}:{}", hostAddress, port == null ? 8080 : port);
    }
}
